import 'dart:async';
import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:open_file_ohos/src/common/open_result.dart';

class OpenFile {
  static const MethodChannel _channel =  MethodChannel('open_file');
  OpenFile._();
  ///[filePath] On web you need to pass the file name to determine the file type
  ///[linuxDesktopName] like 'xdg'/'gnome'
  static Future<OpenResult> open(String? filePath,
      {String? type,
      String? uti,
      Uint8List? webData}) async {
    Map<String, String?> map = {
      "file_path": filePath!,
      "type": type,
      "uti": uti,
    };
    final result = await _channel.invokeMethod('open_file', map);
    final resultMap = json.decode(result) as Map<String, dynamic>;
    return OpenResult.fromJson(resultMap);
  }
}
